package com.kangye.learnteacher.controller;

import com.kangye.learnteacher.entity.Classes;
import com.kangye.learnteacher.entity.Grade;
import com.kangye.learnteacher.entity.Subject;
import com.kangye.learnteacher.entity.TypePaper;
import com.kangye.learnteacher.service.CorrectionService;
import com.kangye.learnteacher.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: learndeduo
 * @description: 批改试卷类
 * @author: 李豪杰
 * @create: 2021-05-17 15:15
 **/
@RestController
@CrossOrigin
@RequestMapping("/Correction")
public class CorrectionController {

    @Autowired
    private CorrectionService correctionService;

    /**
     * 获取学科
     * @param SubjectId
     * @return
     */
    @RequestMapping("/getSubjectId")
    public List<Subject> getSubjectId(Integer SubjectId){
        List<Subject> list = correctionService.getSubjectId(SubjectId);
        return list;
    }


    /**
     * 获取班级
     * @param classesId
     * @return
     */
    @RequestMapping("/getClasses")
    public List<Classes> getClasses(Integer classesId){
        List<Classes> list = correctionService.getClasses(classesId);
        return list;
    }


    /**
     * 获取试卷列表
     * @param page
     * @param limit
     * @param gradeId
     * @param classesId
     * @param subjectId
     * @return
     */
    @RequestMapping("/getStudentParper")
    public ViewJsonObject<Map<String, Object>> getStudentParper(
           Integer page,Integer limit,Integer gradeId,Integer classesId, Integer subjectId,
           Integer spCorrectStatus){
        ViewJsonObject<Map<String, Object>> list = correctionService.getStudentParper(page,limit,classesId,subjectId,gradeId,spCorrectStatus);
        return list;
    }

    /**
     * 获取年级
     * @return
     */
    @RequestMapping("/getGrade")
    public List<Grade> getGrade(){
        List<Grade> list = correctionService.getGrade();
        return list;
    }

    /**
     * 获取需要批改的试卷
     * @param spId
     * @return
     */
    @RequestMapping("/getPaper")
    public List<Map<String, Object>> getPaper(Integer spId,Integer spCorrectStatus){
        List<Map<String, Object>> list = correctionService.getPaper(spId,spCorrectStatus);
        Map<String, Object> map = new HashMap<>();
        if(list.equals("[]")){
            map.put("code","200");
            list.add(map);
            return list;
        }else{
            map.put("code","201");
            list.add(map);
            return list;
        }

    }


    /**
     * 审批试卷
     * @return
     */
    @RequestMapping("/shenpi")
    public String shenpi(Integer score,Integer spid){
        Integer num = correctionService.shenpi(score,spid);
        if(num!=1){
            return "201";
        }
        return "200";
    }
}
